package com.online.teaching.module.teacher.teaches.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.online.teaching.dao.StudentMapper;
import com.online.teaching.dao.TakesMapper;
import com.online.teaching.dao.TeachesMapper;
import com.online.teaching.module.teacher.teaches.domain.vo.GetStudentListVO;
import com.online.teaching.module.teacher.teaches.domain.vo.GetTeachesListVO;
import com.online.teaching.module.teacher.teaches.service.TeacherTeachesService;
import com.online.teaching.pojo.Student;
import com.online.teaching.pojo.Takes;
import com.online.teaching.pojo.Teaches;
import com.online.teaching.utils.SmartBeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName : StudentBlogServiceImpl  //类名
 * @Description :   //描述
 * @Author : YG  //作者
 * @Date: 2020-11-04 13:21  //时间
 */
@Service
public class TeacherTeachesServiceImpl implements TeacherTeachesService {

    @Autowired
    private TeachesMapper teachesMapper;

    @Autowired
    private TakesMapper takesMapper;

    @Autowired
    private StudentMapper studentMapper;


    @Override
    public List<GetTeachesListVO> getTeachesList(Integer teacherId) {
        List<Teaches> teachesList = teachesMapper.getTeachesList(teacherId);
        List<GetTeachesListVO> getTeachesListVOS = SmartBeanUtil.copyList(teachesList, GetTeachesListVO.class);
        return getTeachesListVOS;
    }

    @Override
    public PageInfo<GetStudentListVO> getTeachesStudentList(Integer teachesId, Integer page, Integer size) {
        PageHelper.startPage(page,size);
        List<Integer> teachesStudentList = takesMapper.getTeachesStudentList(teachesId);
        List<Student> students = studentMapper.selectByIdList(teachesStudentList);
        List<GetStudentListVO> getStudentListVOS = SmartBeanUtil.copyList(students, GetStudentListVO.class);
        return new PageInfo(getStudentListVOS);
    }

    @Override
    public int editIntroduction(String intro, Integer teachesId) {
        Teaches teaches=new Teaches();
        teaches.setTeachesId(teachesId);
        teaches.setIntroduction(intro);
        int i = teachesMapper.updateByPrimaryKeySelective(teaches);
        return i;
    }
}
